home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / batch / bat_com / runppdos.asm < prev   
Assembly Source File  |  1989-01-28  |  10KB  |  304 lines

  1. comment *
  2.  
  3.         This is a program to take the place of a simple batch file.  It's
  4.         mostly intended for use with Desqview.  In Desqview, if a program
  5.         runs from a batch file, COMMAND.COM must be loaded to interpret the
  6.         batch file.
  7.  
  8.         If the batch file does nothing more than set up the environment
  9.         and call several programs in sequence, this program can replace it.
  10.         This opens up more room in the window for the main program to use.
  11.  
  12.         (The way you tell Desqview not to load COMMAND.COM is to explicitly
  13.         include a .COM or .EXE extension in the "Program name" field).
  14.  
  15.         This program must be modified and re-asembled for each different
  16.         incarnation.  See lines 62 - 120 below for what must be changed.
  17.  
  18.         This will not work with programs that inspect the default FCB fields
  19.         of the PSP for their first two command line arguments, since I got
  20.         lazy and didn't use int 21h function 29h to parse the command line
  21.         into an FCB.
  22.  
  23.         This is a COM program.  It must be "exe2bin'd".  To create
  24.         RUNPPDOS.COM:
  25.  
  26.         MASM RUNPPDOS;
  27.         LINK RUNPPDOS;
  28.         EXE2BIN RUNPPDOS.EXE RUNPPDOS.COM
  29.  
  30.         This particular incarnation of the program runs a mouse driver,
  31.         Fakey to put PopDOS into split screen mode, and then PopDOS
  32.  
  33.         Jon Fleming (BIX: jfleming)     12/20/88
  34.  
  35.         Released into the public domain 1/29/89
  36. *
  37.  
  38.         cr      equ     0dh
  39.         lf      equ     0ah
  40.         space   equ     20h
  41.         tab     equ     9
  42.  
  43.         stdin   equ     0
  44.         stdout  equ     1
  45.         stderr  equ     2
  46.         stdaux  equ     3
  47.         stdprn  equ     4
  48.  
  49.         stack_size      equ     256     ;bytes set aside for stack
  50.  
  51. stack   segment stack                   ;this just keeps the linker quiet
  52. stack   ends
  53.  
  54.         program group   code,data
  55.  
  56. code    segment
  57.  
  58. data    segment para    ;environment has to be paragraph aligned
  59.  
  60.  
  61.  
  62. ;Put the environment you want here.  Each string should be CAPITALIZED,
  63. ;and terminated with a 00 byte.  Terminate the whole environment with
  64. ;two 00 bytes.
  65.  
  66. ;Note that you must set up the WHOLE environment, this program is not
  67. ;smart enough to copy anything from its environment.  A PATH and COMSPEC
  68. ;are the minimum you should set up.
  69.  
  70. environment     label   byte
  71.         db      "PATH=E:\;C:\BATCH;C:\DOS;F:\;G:\;H:\;I:\;C:\",0
  72.         db      "PROMPT=$P$G",0
  73.         db      "COMSPEC=E:\COMMAND.COM",0
  74.         db      0
  75.  
  76.  
  77.         
  78. ;put the FULL PATHNAME of the first program you want to run here, again
  79. ;terminated by a 00 byte.  BE SURE to include the .COM or .EXE
  80.         
  81. mouse_driver_name       db      "C:\ORGANIZE\MOUSE\MOUSE.COM",0
  82.  
  83. ;Here's how a command tail is handled. First a length byte (not including
  84. ;the length byte itself or the carriage return at the other end).
  85.  
  86. mouse_driver_cmd_tail   db      end_md_cmd_tail-mouse_driver_cmd_tail-2
  87. ;then the command tail itself, terminated by a carriage return
  88.                         db      " 2 ser bon",cr
  89. end_md_cmd_tail         label   byte
  90.  
  91. keyfake_name            db      "E:\FAKEY.COM",0
  92.  
  93. keyfake_cmd_tail        db      end_keyfake_cmd_tail-keyfake_cmd_tail-2
  94.                         db      " F3",cr
  95. end_keyfake_cmd_tail    label   byte
  96.  
  97. ;and a third program, with no command tail
  98.  
  99. popdos_name             db      "C:\ORGANIZE\MOUSE\POPDOS.EXE",0
  100.  
  101. ;a null command line for any programs that don't need a command line
  102.  
  103. null_cmd_tail           db      0,cr
  104.  
  105.  
  106.  
  107. ;Now we have a table of addresses of the program names and their
  108. ;command lines
  109.  
  110. program_table   label   word
  111. mouse_name_addr         dw      offset program:mouse_driver_name
  112. mouse_cmd_tail_addr     dw      offset program:mouse_driver_cmd_tail
  113. keyfake_name_addr       dw      offset program:keyfake_name
  114. keyfake_cmd_tail_addr   dw      offset program:keyfake_cmd_tail
  115. popdos_name_addr        dw      offset program:popdos_name
  116. popdos_cmd_tail_addr    dw      offset program:null_cmd_tail
  117.  
  118. ;and the program table is terminated by a 0000 word
  119.  
  120. end_program_table       dw      0
  121.  
  122.  
  123.  
  124. ;The following is a block of parameters for the MS-DOS function that
  125. ;executes the programs
  126.  
  127. exec_parameter_block    label   byte
  128. environment_paragraph   dw      ?
  129. cmd_tail_offset         dw      ?
  130. cmd_tail_segment        dw      ?
  131. fcb_1_offset            dw      -1      ;no FCBs set up
  132. fcb_1_segment           dw      -1
  133. fcb_2_offset            dw      -1
  134. fcb_2_segment           dw      -1
  135.  
  136.  
  137.  
  138. ;A simple error message
  139.  
  140. error_msg               db      cr,lf,"EXEC failed, AL= 0"
  141. error_code      db      2 dup (?)
  142.                 db      "h",cr,lf
  143. error_msg_length        equ     $ - error_msg
  144.  
  145.  
  146.  
  147. ;storage for the SS and SP registers which will be trashed by MS-DOS
  148. :(at least 2.x, I hear 3.x is nicer, but I'm being safe)
  149.  
  150. stack_segment   dw      ?
  151. stack_pointer   dw      ?
  152.  
  153.  
  154.  
  155. ;and a marker for the end of the program
  156.  
  157. end_program     label   byte            ;note that the data will be AFTER
  158.                                         ;the code after linking
  159. data    ends
  160.  
  161.  
  162.  
  163. ;Our Program Segment Prefix
  164.  
  165.         org     2ch
  166. our_envir_seg   dw      ?
  167.  
  168.  
  169.  
  170. ;Program itself
  171.         org     100h
  172.         assume  cs:program,ds:program,es:program,ss:program
  173.  
  174. begin:
  175.         mov     es,our_envir_seg
  176.         assume  es:nothing
  177.         mov     ah,49h
  178.         int     21h                     ;release our environment
  179.  
  180.         mov     ax,cs
  181.         mov     es,ax                   ;restore ES
  182.         assume  es:program
  183.  
  184.         mov     bx,offset program:end_program   ;end of us in bytes
  185.         add     bx,stack_size           ;add on stack size
  186.  
  187.         cli                             ;still some early 8088s out there that
  188.                                         ;need this
  189.         mov     sp,bx                   ;relocate stack
  190.         sti
  191.  
  192.         add     bx,15
  193.         shr     bx,1
  194.         shr     bx,1
  195.         shr     bx,1
  196.         shr     bx,1                    ;round our size up to paragraphs
  197.  
  198.         mov     ah,4ah
  199.         int     21h                     ;shrink our memory allocation to make
  200.                                         ;room for other programs
  201.  
  202.         mov     bx,offset program:environment
  203.         shr     bx,1
  204.         shr     bx,1
  205.         shr     bx,1
  206.         shr     bx,1                    ;BX has offset of environment for
  207.                                         ;other programs (in paragraphs)
  208.  
  209.         mov     ax,ds
  210.         add     ax,bx                   ;AX has absolute paragraph of
  211.                                         ;environment for other programs
  212.  
  213.         mov     environment_paragraph,ax        ;set up pointer to environment
  214.  
  215.         mov     cmd_tail_segment,ds     ;set up segment of pointer to command
  216.                                         ;tail
  217.  
  218.         mov     bp,offset program:program_table ;point to pointer to name of
  219.                                                 ;first program to run
  220.  
  221. loop_over_programs:
  222.         mov     dx,[bp]                 ;load pointer to name of first
  223.                                         ;program to run
  224.         or      dx,dx
  225.         jz      exit                    ;zero means we've reached end of table
  226.  
  227.         inc     bp
  228.         inc     bp                      ;point to pointer to command tail
  229.         mov     cx,[bp]
  230.         mov     cmd_tail_offset,cx      ;set up offset of pointer to command
  231.                                         ;tail
  232.  
  233.         inc     bp
  234.         inc     bp                      ;point to pointer to next program name
  235.  
  236.         push    bp                      ;save for later
  237.  
  238.         mov     bx,offset program:exec_parameter_block  ;pointer
  239.                                         ;to parameter block
  240.  
  241.         mov     ax,4b00h                ;exec function, run program
  242.  
  243.         mov     stack_segment,ss
  244.         mov     stack_pointer,sp        ;EXEC trashes these
  245.  
  246.         int     21h
  247.         assume  ds:nothing,es:nothing,ss:nothing
  248.  
  249.         cli                             ;for 8088s with bug
  250.         mov     ss,stack_segment
  251.         assume  ss:program
  252.         mov     sp,stack_pointer
  253.         sti                             ;restore stack segment and pointer
  254.  
  255.         mov     bx,cs
  256.         mov     ds,bx
  257.         assume  ds:program              ;restore data segment
  258.  
  259.         mov     es,bx
  260.         assume  es:program              ;restore extra segment
  261.  
  262.         jnc     get_ready_for_next_prog ;now we can see if the EXEC worked
  263.  
  264.         mov     dl,al                   ;whoops, it didn't; save error code
  265.  
  266.         and     al,0Fh                  ;get one digit worth
  267.         daa                             ;add 6 if A through F
  268.         add     al,0F0h                 ;set carry if A-F
  269.         adc     al,40h                  ;convert to ASCII
  270.  
  271.         mov     error_code+1,al         ;and save second digit
  272.  
  273.         rol     dl,1
  274.         rol     dl,1
  275.         rol     dl,1
  276.         rol     dl,1                    ;get other digit-worth of the byte
  277.                                         ;into position
  278.         mov     al,dl
  279.         and     al,0Fh                  ;get one digit worth
  280.         daa                             ;add 6 if A through F
  281.         add     al,0F0h                 ;set carry if A-F
  282.         adc     al,40h                  ;convert to ASCII
  283.  
  284.         mov     error_code, al          ;and save first digit
  285.  
  286.         mov     dx,offset program:error_msg
  287.         mov     cx,error_msg_length
  288.         mov     bx,stderr
  289.         mov     ah,40h
  290.         int     21h                     ;display error message
  291.  
  292. get_ready_for_next_prog:
  293.         pop     bp                      ;restore pointer to pointer to next
  294.                                         ;program name
  295.  
  296.         jmp     loop_over_programs      ;go do next program
  297.  
  298. exit:
  299.         mov     ax,4c00h
  300.         int     21h
  301.  
  302. code    ends
  303. end     begin
  304.